<?php
/**
 * Object Relational Persistence Mapping Class for table: working_calendar
 *
 * @package	com.athena
 * @author	LHV
 */
class WorkingCalendar extends ORDataObject {

	/**#@+
	 * Fields of table: calendar_event mapped to class members
	 */
	var $calendar_id	= '';
	var $creator_id		= '';
	var $start_date		= '';
	var $end_date		= '';
	var $person_id		= '';
	var $monday 		= '';
	var $tuesday 		= '';
	var $wednesday 		= '';
	var $thursday 		= '';
	var $friday 		= '';
	var $saturday 		= '';
	var $sunday 		= '';
	/**#@-*/

	/**
	 * DB Table
	 */
	var $_table = 'working_calendar';

	/**
	 * Primary Key
	 */
	var $_key = 'calendar_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'WorkingCalendar';

	/**
	 * Handle instantiation
	 */
	function WorkingCalendar() {
		parent::ORDataObject();
	}

	
	/**#@+
	 * Field: start_date, time formatting
	 */
	function get_start_date() {
		return $this->_getDate('start_date');
	}
	function set_start_date($date) {
		$this->_setDate('start_date',$date);
	}
	/**#@-*/

	/**#@+
	 * Field: end_date, time formatting
	 */
	function get_end_date() {
		return $this->_getDate('end_date');
	}
	function set_end_date($date) {
		$this->_setDate('end_date',$date);
	}
	/**#@-*/
	
	public function getCalendar($userId, $date) {
		$ds = new Datasource_sql();
		$sql = array (
			'cols' 		=> "calendar_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday",
			'from'		=> $this->_table,
			'where'		=> "person_id = $userId AND (date('$date') BETWEEN start_date AND end_date) "				
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function addCalendar($calendarId, $creatorId, $startDate, $endDate, $personId,
		$monday, $tuesday, $wednesday, $thursday, $friday, $saturday, $sunday){
		$data = array(
			'creator_id'	=> $creatorId,
			'start_date'	=> $startDate,
			'end_date'	 	=> $endDate,
			'person_id'	 	=> $personId,
			'monday'		=> $monday,
			'tuesday' 		=> $tuesday,
			'wednesday' 	=> $wednesday,
			'thursday' 		=> $thursday,
			'friday' 		=> $friday,
			'saturday' 		=> $saturday,
			'sunday' 		=> $sunday
		);
		if(isset($calendarId) && $calendarId != ''){
			$this->setup($calendarId);
		}
		$this->populateArray($data);
		$this->persist();
		return $this->calendar_id;
	}	
}
?>
